<?php 
/**
 * eBay Label Printing Program Backoffice Menu Sub Controller 
 * This is the controller for Administrator management
 * First Version Finished on 2012-03-31
 * @package  eBayLabelPrinter
 * @category Controller
 * @author   Norman Dong <norman.dong@hotmail.com>
 * @version  Initial
 * @copyright LeadCasket.com
 * @link     www.leadcasket.com
 * @license  Commercial
 */
class Backoffice_BackofficemenuController extends Zend_Controller_Action
{
	
	/**
	 * Init function ,only setup the Backoffice layout
	 *
	 */	
    public function init(){
    	$this->_helper->layout->setLayout('backofficelayout');
	}
	
	/**
	 * Index Function , doing Nothing 
	 *
	 */
    public function indexAction(){
	    
    	echo "Home Page of Backoffice Menu  ";
	    
	}
	/**
	 * addBackofficeMenu Function, Add backoffice menu into the Database
	 *
	 */
	public function addBackofficeMenuAction(){
		
		$addMenuForm = new Form_System_Backofficemenu();
		$this->view->addmenuform = $addMenuForm;
		
		if($this->getRequest()->isPost()){
				
			$formData = $this->getRequest()->getPost();
			if($addMenuForm->isValid($formData)){
				
				$parentMenuID  = $addMenuForm->getValue('id_parent_backoffice_menu');
				$menuOrder  = $addMenuForm->getValue('order_backoffice_menu');
				$menuName  = $addMenuForm->getValue('name_backoffice_menu');
				$menuLink  = $addMenuForm->getValue('link_backoffice_menu');
				$menuLevel  = $addMenuForm->getValue('level_backoffice_menu');
				$menuIcon  = $addMenuForm->getValue('icon_backoffice_menu');
				
				$backofficeMenu = new Model_DbTable_System_Backofficemenu();
				$backofficeMenu->addBackofficeMenu($parentMenuID, $menuOrder, $menuName, $menuLink, $menuLevel, $menuIcon);
				$this->_redirect('backoffice_backofficemenu/manage-backoffice-menu');
				
			}
		}
		
		
	}
	/**
	 * editBackofficeMenu Function, edit Backoffice Menu structure and links
	 *
	 */
	public function editBackofficeMenuAction(){
		
		$editMenuForm = new Form_System_Backofficemenu();
		$this->view->editmenuform = $editMenuForm;
		
		if($this->getRequest()->isPost()){
		
			$formData = $this->getRequest()->getPost();
			if($editMenuForm->isValid($formData)){
				$menuID = $editMenuForm->getValue('id_backoffice_menu'); 
				$parentMenuID  = $editMenuForm->getValue('id_parent_backoffice_menu');
				$menuOrder  = $editMenuForm->getValue('order_backoffice_menu');
				$menuName  = $editMenuForm->getValue('name_backoffice_menu');
				$menuLink  = $editMenuForm->getValue('link_backoffice_menu');
				$menuLevel  = $editMenuForm->getValue('level_backoffice_menu');
				$menuIcon  = $editMenuForm->getValue('icon_backoffice_menu');
				
				$backofficeMenu = new Model_DbTable_System_Backofficemenu();
				$backofficeMenu->updateBackofficeMenu($menuID, $parentMenuID, $menuOrder, $menuName, $menuLink, $menuLevel, $menuIcon);
				unset($backofficeMenu);
				$this->_redirect('backoffice_backofficemenu/manage-backoffice-menu');
				
				
			}
			else{
				$editMenuForm->populate($formData);
			}
		}
		else{
			$menuID = $this->_getParam('idmenu');
			$backofficeMenu = new Model_DbTable_System_Backofficemenu();
			$editMenuForm->populate($backofficeMenu->getBackofficeMenu($menuID));
		}	
		
	}
	/**
	 * manageBackofficeMenu Function, using Jquery table lister to give a menu list 
	 * No structure at the moment, pure list 
	 *@todo need to add tree structure for the menu 
	 */
	public function manageBackofficeMenuAction(){
		$backofficeMenuList = new Model_DbTable_System_Backofficemenu();
		$this->view->backofficemenu = $backofficeMenuList->listMenu();
	}
	/**
	 * deleteBackofficeMenu Function, delete backoffice menu from the Database
	 *
	 */
	public function deleteBackofficeMenuAction(){
		$menuID = $this->_getParam('idmenu');
		$backofficeMenuList = new Model_DbTable_System_Backofficemenu();
		$backofficeMenuList->deleteBackofficeMenu($menuID);
		echo "Menu ID:".$menuID."Have been Deleted";
		
		
	}
 		

}
?>